package android.video.online.adapter;

import android.video.online.BasicAdapter;
import android.video.online.BasicViewHolder;
import android.video.online.R;
import android.video.online.model.Category;
import android.video.online.ui.BasicActivity;
import android.video.online.ui.classify.ClassifyContract;
import android.video.online.viewholder.ClazzManageViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Jay on 2017/8/13.
 */

public class ClassifyAdapter extends BasicAdapter<Category> {
    ClassifyContract.Presenter presenter;

    public ClassifyAdapter(BasicActivity context, List<Category> mData, ClassifyContract.Presenter presenter) {
        super(context, mData);
        this.presenter = presenter;
    }

    @Override
    protected void setDataView(BasicViewHolder holder, final Category category) {
        TextView tvTitle = (TextView) holder.getParentView().findViewById(R.id.tv_clazz_title);
        tvTitle.setText(category.getTitle());
        tvTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(presenter != null){
                    presenter.classifyItemClick(category);
                }
            }
        });
    }

    @Override
    public BasicViewHolder createViewHolder() {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_classify, null);
        return new ClazzManageViewHolder(inflate);
    }
}
